package com.emcom.gotour.dao.ibatis;

import java.util.List;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.emcom.gotour.dao.TourContentDao;
import com.emcom.gotour.enums.TourType;
import com.emcom.gotour.po.TourContent;
import com.ibatis.sqlmap.client.SqlMapClient;

public class IbatisTourContentDao implements TourContentDao {

	private SqlMapClientTemplate sqlMapClientTemplate;

	public TourContent query(long id) {
		TourContent tourContent = new TourContent();
		tourContent.setId(id);
		List<TourContent> tourContentList = query(tourContent);
		if(tourContentList.size() == 1) {
			return tourContentList.get(0);
		}
		return null;
	}

	public List<TourContent> query(TourContent tourContent) {
		return sqlMapClientTemplate.queryForList("TourContent.query", tourContent);
	}

	public void update(TourContent tourContent) {
		sqlMapClientTemplate.update("TourContent.update", tourContent);
	}

	public void insert(TourContent tourContent) {
		sqlMapClientTemplate.insert("TourContent.insert", tourContent);
	}

	public void delete(TourContent tourContent) {
		sqlMapClientTemplate.delete("TourContent.delete", tourContent);
	}

	public List<String> queryCategory(TourType tourType) {
		return sqlMapClientTemplate.queryForList("TourContent.queryCategory", tourType.name());
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClientTemplate = new SqlMapClientTemplate();
		this.sqlMapClientTemplate.setSqlMapClient(sqlMapClient);
	}

}
